//
// Created by Administrator on 2022/1/2 0002.
//
#include <iostream>
#include <cstring>
#include "t_struct.h"

//测试结构体内部的为字段
//指定占位bit
void test_struct_bitfield(){
    using namespace std;
    struct HSJ{
        unsigned int SN:4;//4 bit for SN value
        unsigned int :4;  //4 bit unused 没有变量名，仅仅占位内存，无法使用
        bool goodIn:1;//1 bit for goodIn
        bool goodTorgle:1;//1 bit for goodTorgle
    };
    //在c++里面，struct可以省略
    struct HSJ vb  = {
            .SN = 10,
            .goodIn = true,
            .goodTorgle = false
    };

    cout<<vb.SN<<endl<<vb.goodIn<<endl<<vb.goodTorgle<<endl;

    struct inflatable {
        char name[20];
        int age;
        double money;
        string addr;
    };

    struct inflatable *it = new inflatable;
    strcpy(it->name,"hsj is smart!");
    it->age = 18;
    (*it).money = 100000000.0;
    it->addr = "kunming city";

    cout<<"name is:"<<it->name<<endl;
    cout<<"age is:"<<it->age<<endl;
    cout<<"money is:"<<(*it).money<<endl;
    cout<<"addr is:"<<it->addr<<endl;

//    手动释放内存空间
    delete it;

}